{include file="public/header"/}

<title>{:lang('申请代理')}</title>
<header id="header" class="mui-bar mui-bar-nav">
    <div class="mui-pull-left PopupNavigation">
        <img src="/static/home/bl_1.png" alt="">
    </div>
    <h1 class="mui-title">{:lang('申请代理')}</h1>
    <div class="mui-pull-right" style="display: none;">
        <div class="mui-switch mui-active" >
            <div class="mui-switch-handle"></div>
        </div>
    </div>
</header>   
<style type="text/css">
    .bjco{
        background-color: #999;
    }
</style>
{include file="public/menu" /}
<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
        <div class="mui-scroll">
            <div class="applicaageBox">
                <div class="applicaageTl">
                    <span class="span_1"></span>
                    <span class="span_2">{:lang($user['level'])}</span>
                    <span class="span_1">&nbsp;{:lang('筹码')}</span>
                    <span class="span_3">{$user['chip']}</span>
                </div>
                <div class="applicaageContBox clearfix">
                    {foreach :config('base.level') as $k=>$v}
                    {if $k > 0}
                    <div class="applicaageContList">
                        <div class="applicaageCont {if $usertmp['level'] < $k}click_switch{else/}bjco{/if}" data-id="{$k}">
                            <div>${$v.chip}</div>
                            <div>{:lang($v['name'])}</div>
                        </div>
                    </div>
                    {/if}
                    {/foreach}
                    </div>
                <form id="subForm">
                    <div class="applicaageAnbox">
                        <input type="number" style="display: none;" name="integral" autocomplete="off" class="gisteinput" placeholder="{:lang('请输入整数积分数量')}">
                    </div>
                    <div class="applicaageAnbox">
                        <input type="hidden" name="level_id" value="0" autocomplete="off" />
                        <button class="applicaageAn disabledClickSubmit" type="button">{:lang('购买')}</button>
                    </div>
                <input type="hidden" name="__hash__" value="d940542cbda4db134229b36f8f0c0d58_f1bed47a90828f9fbb8ed5ccd5079669" /></form>
            </div>

            <div class="staataTl">{:lang('申请代理记录')}</div>
            <div class="staataTableBox">
                <table class="tabletada" border="0" cellspacing="" cellpadding="">
                    <thead>
                        <tr>
                            <th>{:lang('申请时间')}</th>
                            <th>{:lang('代理级别')}</th>
                        </tr>
                    </thead>
                    <tbody id="content"><tr>
 
                    </tbody>
                </table>
            </div>

        </div>


    </div>

    {include file="public/footer"/}

    <script>
        mui('.mui-scroll-wrapper').scroll({
            deceleration: 0.0005
        });
        mui('body').on('tap', '.click_switch', function(){
           $(this).addClass('applicaageContActive');
           $('input[name="level_id"]').val($(this).data('id'));
           $(this).parent('.applicaageContList').siblings('.applicaageContList').find('.applicaageCont').removeClass('applicaageContActive');

           $('.disabledClickSubmit').removeClass('disabledClickSubmit').addClass('subForm');
        });
        var mask=mui.createMask(),isSub = true;
        mui('body').on('tap', '.subForm', function() {
            var obj = $(this);
            if(isSub) {
                isSub = false;
                var data = $('#subForm').serialize();
                var url = "{:url('agent')}";
                mui.showLoading("提交中","div");
                mask.show();//显示遮罩层
                $.post(url, data, function(data) {
                    mask.close();//关闭遮罩层
                    mui.hideLoading();
                    if(data.status == 0) {
                        isSub = true;
                        mui.toast(data.msg, {
                            duration: 'long',
                            type: 'div'
                        });
                    } else if(data.status == 1) {
                        mui.toast(data.msg, {
                            duration: '2000',
                            type: 'div'
                        });
                        setTimeout(function() {
                            window.location.href = data.url;
                        }, 2000);
                    }
                });
            }
        });

        var stop = true;
        function ajax_get_invest_log() {
        if (stop == true) {
            $('#investLogContent').html('');
            stop = false;
            $.ajax({
                type: "POST",
                url: "{:url('Level/levelLog')}",
                success: function(data) {
                    mui.hideLoading();
                    if (data.status == 0) {
                        mui.toast(data.msg, {
                            duration: 'long',
                            type: 'div'
                        });
                        return;
                    }
                    $('.loadAdd').hide();
                    // layer.close(getMoreLoad);
                    if ($.trim(data) == '') {
                        stop=false;
                    } else {
                        stop = true;
                        let html = '';
                        for(var i = 0;i<data.list.length;i++){
                            html += '<tr><td>'+data.list[i].created+'</td>';
                            html += '<td>'+data.list[i].order_id+'</td>';
                            html += '</tr>';
                        }
                        console.log(html);
                        $('#content').append(html);
                    }
                },error:function(){
                    mui.toast('网络失败，请刷新后重试',{ duration:'long', type:'div' })
                }
            });
        }
    }
    $(function(){
        ajax_get_invest_log();
    });


    </script>
</body>

</html>